<template>
    <van-nav-bar title="短信验证码登录" />
    <van-form @submit="onSubmit">
        <van-cell-group inset>
            <van-field v-model="username" name="username" label="国家和地区" placeholder="中国"
                :rules="[{ required: true, message: '请填写用户名' }]" />
            <van-field v-model="password" name="password" label="手机号" placeholder="手机号"
                :rules="[{ required: true, message: '请填写用户名' }]" />

            

        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="primary" native-type="submit">
                登录
            </van-button>

        </div>
    </van-form>
    <p>未注册的手机号验证后将自动注册<span style="color: deepskyblue; margin-left: 3rem;">账号密码登录</span></p>
</template>

<script setup>
import { loginApi } from '@/api/api'
import { ref } from 'vue';
const username = ref('');
const password = ref('');
import { showToast } from 'vant';
import { useRouter } from 'vue-router';
const  router =useRouter()
const onSubmit = (values) => {
loginApi(username.value,password.value).then(res=>{
    console.log('数据',res);
    if(username.value||password.value){
         showToast('登录成功');
         router.push('/home/my')
    }
    else{
        showToast('登录失败');
    }
})
};
</script>

<style lang="scss" scoped></style>